package producer;

import queue.Queue1;


/**
 * @author Xu,
 * @data 2020/12/19，
 * @time 16:44
 * 生产者负责生产大于20亿的正整数；
 */
public class Producer implements Runnable{
    private long num;
    private int count = 0;
    private Queue1 queue;
    private int perNum;
    private StringBuffer stringBuffer = new StringBuffer();
    public Producer(){
    }
    public Producer(Queue1 queue, int perNum){
        this.queue = queue;
        this.perNum = perNum;
    }
    /**
     * 获取随机生成的大于20亿的正整数；
     */
    public long getRandom(){
        stringBuffer.append(String.valueOf(2+ (int)(Math.random()*8)));
        for(int i=1; i<10; i++){
            stringBuffer.append(String.valueOf((int)(Math.random()*10)));
        }
        num = Long.parseLong(stringBuffer.toString());
        stringBuffer.setLength(0);
        count++;
        return num;
    }

    public long getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    @Override
    public void run(){
        for(int i=0;i<perNum;i++){
            queue.getPut(getRandom());
            //System.out.println("生产者doing");
        }
    }

    public int getCount() {
        return count;
    }
}
